﻿using System;
using System.Windows;
using System.Reflection;

namespace Rabbit.Themes
{
    public static class ThemeManager
    {
        private static string currentTheme;
        //public static ResourceDictionary GetTheme(string themeName)
        //{
        //    if (themeName != null)
        //    {
        //        Assembly assembly = Assembly.LoadFrom("Rabbit.Themes.dll");
        //        string packageUri = string.Format(@"/Rabbit.Themes;component/{0}/theme.xaml", themeName);

        //        return Application.LoadComponent(new Uri(packageUri, UriKind.Relative)) as ResourceDictionary;
        //    }
        //    return null;
        //}
        private static System.Collections.Generic.List<Theme> themeList = new System.Collections.Generic.List<Theme>();
        static ThemeManager()
        {
            themeList.Add(new Theme() { Name = "默认", Value = "Default" });
            themeList.Add(new Theme() { Name = "低调黑", Value = "Win7" });
            themeList.Add(new Theme() { Name = "粉粉嫩", Value = "Pink" });
            themeList.Add(new Theme() { Name = "清新绿", Value = "Green" });
            themeList.Add(new Theme() { Name = "诱惑橙", Value = "Orange" });
            themeList.Add(new Theme() { Name = "婚庆红", Value = "Marriage" });

#if DEBUG
            themeList.Add(new Theme() { Name = "丑陋白", Value = "UglyWhite" });
#endif
        }
        public static void ApplyTheme(this Application app, string themeName)
        {
            if (currentTheme != themeName && themeName != null)
            {
                if (themeList.FindIndex(t => t.Value == themeName) == -1)
                {
                    themeName = "Default";
                }

                Assembly assembly = Assembly.LoadFrom("Rabbit.Themes.dll");
                string packageUri = string.Format(@"/Rabbit.Themes;component/{0}/theme.xaml", themeName);

                app.Resources.MergedDictionaries.Clear();
                app.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri(packageUri, UriKind.Relative)) as ResourceDictionary);
                currentTheme = themeName;
            }
        }

        public static System.Collections.Generic.List<Theme> GetThemeList()
        {
            return themeList;
        }

    }

    public class Theme{
        public string Name { get; set; }
        public string Value { get; set; }
    }
}
